﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class get : System.Web.UI.Page
{
    protected BLL.LostAndFound blllaf = new BLL.LostAndFound();
    protected void Page_Load(object sender, EventArgs e)
    {
        Bind(1);
    }
    protected void Bind(int pagenum)
    {
        //得到总页数
        int count = blllaf.getPCByUserId(0, "招领启事");
        if (pagenum < 1)
        {
            pagenum = 1;
        }
        if (pagenum > count)
        {
            pagenum = count;
        }
        //别要忘了这个
        btnpre.Enabled = true;
        btnnext.Enabled = true;
        if (pagenum == 1)
        {
            btnpre.Enabled = false;
        }
        if (pagenum == count)
        {
            btnnext.Enabled = false;
        }
        string ordercondition = " [Time] desc";
        if (ViewState["order"] != null)
        {
            ordercondition = ViewState["order"].ToString();
        }
        List<MODEL.LostAndFound> models = blllaf.getAll("招领启事", pagenum, ordercondition);
        foreach (MODEL.LostAndFound laf in models)
        {
            if (laf.Feature.Length > 12)
                laf.Feature = laf.Feature.Substring(0, 12) + "......";
            //图片为空的时候，让它的image字段等于默认的图片
            //if (string.IsNullOrWhiteSpace(laf.Image))
            //{
            //    laf.Image = "noimg.png";
            //}
        }
        rpGet.DataSource = models;
        rpGet.DataBind();
        pageNum.Text = pagenum.ToString();
        pageCount.Text = count.ToString();
    }

    //按时间
    protected void orderByTime_Click(object sender, EventArgs e)
    {
        if (orderByTime.Text == "时间↑")
        {
            orderByTime.Text = "时间↓";
            ViewState["order"] = " [Time]";
            Bind(1);
        }
        else
        {
            orderByTime.Text = "时间↑";
            ViewState["order"] = " [Time] desc";
            Bind(1);
        }
    }

    //上一页
    protected void btnpre_Click(object sender, EventArgs e)
    {
        int currentpage = Convert.ToInt32(pageNum.Text);
        currentpage--;
        Bind(currentpage);
    }
    //下一页
    protected void btnnext_Click(object sender, EventArgs e)
    {
        int currentpage = Convert.ToInt32(pageNum.Text);
        currentpage++;
        Bind(currentpage);
    }
    //跳转
    protected void btnjump_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            int pagenum = Convert.ToInt32(txtjump.Text);
            Bind(pagenum);
        }
    }
}